package com.c8a.stream.service.impl;

import com.c8a.stream.service.IMessageProvider;
import lombok.extern.log4j.Log4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @Program: springcloud2022
 * @Description: MessageProviderImpl
 * @Author: c8a
 * @Email: 1912327276@qq.com
 * @Create: 2022-05-12 23:39
 **/

@EnableBinding(Source.class)//实现了对消息通道（channel）的绑定   定义消息的推送管道，  源头
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {

        String uuid = UUID.randomUUID().toString();

        output.send(MessageBuilder.withPayload(uuid).build());
        System.out.println("uuid=" + uuid);
        return uuid;
    }
}
